package com.ruoyi.zhgd.controller;

import java.util.List;
import java.util.Arrays;
import java.util.Map;

import com.ruoyi.zhgd.domain.vo.NAsphaltDataWeightPageVo;
import com.ruoyi.zhgd.domain.vo.NAsphaltProduceWeightVo;
import lombok.RequiredArgsConstructor;
import javax.servlet.http.HttpServletResponse;
import javax.validation.constraints.*;
import cn.dev33.satoken.annotation.SaCheckLogin;
import org.springframework.web.bind.annotation.*;
import org.springframework.validation.annotation.Validated;
import com.ruoyi.common.annotation.RepeatSubmit;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.PageQuery;
import com.ruoyi.common.core.domain.R;
import com.ruoyi.common.core.validate.AddGroup;
import com.ruoyi.common.core.validate.EditGroup;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.zhgd.domain.vo.NAsphaltDataWeightVo;
import com.ruoyi.zhgd.domain.bo.NAsphaltDataWeightBo;
import com.ruoyi.zhgd.service.INAsphaltDataWeightService;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 沥青拌合站数据
 *
 * @author zyb
 * @date 2023-09-06
 */
@Validated
@RequiredArgsConstructor
@RestController
@RequestMapping("/zhgd/asphaltDataWeight")
public class NAsphaltDataWeightController extends BaseController {

    private final INAsphaltDataWeightService iNAsphaltDataWeightService;

    /**
     * 查询沥青拌合站数据列表
     */
    @SaCheckLogin
    @GetMapping("/list")
    public TableDataInfo<NAsphaltDataWeightVo> list(NAsphaltDataWeightBo bo, PageQuery pageQuery) {
        return iNAsphaltDataWeightService.queryPageList(bo, pageQuery);
    }

    /**
     * 导出沥青拌合站数据列表
     */
    @SaCheckLogin
    @Log(title = "沥青拌合站数据", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(NAsphaltDataWeightBo bo, HttpServletResponse response) {
        List<NAsphaltDataWeightVo> list = iNAsphaltDataWeightService.queryList(bo);
        ExcelUtil.exportExcel(list, "沥青拌合站数据", NAsphaltDataWeightVo.class, response);
    }

    /**
     * 获取沥青拌合站数据详细信息
     *
     * @param id 主键
     */
    @SaCheckLogin
    @GetMapping("/{id}")
    public R<Map<String, NAsphaltDataWeightVo>> getInfo(@NotNull(message = "主键不能为空")
                                     @PathVariable String id) {
        return R.ok(iNAsphaltDataWeightService.queryById(id));
    }

    /**
     * 新增沥青拌合站数据
     */
    @SaCheckLogin
    @Log(title = "沥青拌合站数据", businessType = BusinessType.INSERT)
    @RepeatSubmit()
    @PostMapping()
    public R<Void> add(@Validated(AddGroup.class) @RequestBody NAsphaltDataWeightBo bo) {
        return toAjax(iNAsphaltDataWeightService.insertByBo(bo));
    }

    /**
     * 修改沥青拌合站数据
     */
    @SaCheckLogin
    @Log(title = "沥青拌合站数据", businessType = BusinessType.UPDATE)
    @RepeatSubmit()
    @PutMapping()
    public R<Void> edit(@Validated(EditGroup.class) @RequestBody NAsphaltDataWeightBo bo) {
        return toAjax(iNAsphaltDataWeightService.updateByBo(bo));
    }

    /**
     * 删除沥青拌合站数据
     *
     * @param ids 主键串
     */
    @SaCheckLogin
    @Log(title = "沥青拌合站数据", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public R<Void> remove(@NotEmpty(message = "主键不能为空")
                          @PathVariable String[] ids) {
        return toAjax(iNAsphaltDataWeightService.deleteWithValidByIds(Arrays.asList(ids), true));
    }

    /**
     * 生产数据监控重量分页
     */
    @SaCheckLogin
    @GetMapping("/page")
    public TableDataInfo<NAsphaltDataWeightPageVo> page(NAsphaltDataWeightBo bo, PageQuery pageQuery) {
        return iNAsphaltDataWeightService.page(bo, pageQuery);
    }

    /**
     * 总量校核
     * @param bo
     * @param pageQuery
     * @return
     */
    @SaCheckLogin
    @GetMapping("/produceWeight")
    public TableDataInfo<NAsphaltProduceWeightVo> produceWeight(NAsphaltDataWeightBo bo, PageQuery pageQuery) {
        return iNAsphaltDataWeightService.produceWeight(bo, pageQuery);
    }

    /**
     * 生产数据监控重量列表
     */
    @SaCheckLogin
    @GetMapping("/weightList")
    public R<List<NAsphaltDataWeightVo>> weightList(NAsphaltDataWeightBo bo) {
        return R.ok(iNAsphaltDataWeightService.weightList(bo));
    }

    /**
     * 生产数据监控重量列表-按天统计
     */
    @SaCheckLogin
    @GetMapping("/dayWeightList")
    public Map<String, Object> dayWeightList(NAsphaltDataWeightBo bo) {
        return iNAsphaltDataWeightService.dayWeightList(bo);
    }

    /**
     * 首页数据汇总
     */
    @SaCheckLogin
    @GetMapping("/homeCount")
    public Map<String, Object> homeCount(NAsphaltDataWeightBo bo) {
        return iNAsphaltDataWeightService.homeCount(bo);
    }
}
